import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:path_provider/path_provider.dart';

class FileUtils{

  //选择文件夹
  static Future<String?> pickFolder() async {
    String? selectedDirectory = await FilePicker.platform.getDirectoryPath();
    return selectedDirectory;
  }

  ///选择文件
  static Future<FilePickerResult?> pickFile() async {
    try {
      FilePickerResult? result = await FilePicker.platform.pickFiles(
        allowMultiple: false, // 是否允许选择多个文件/文件夹
      );
      return result;
    } catch (e) {
      // 处理异常
      print("Error picking folder: $e");
    }
    return null;
  }

  ///获取当前应用的文件位置
  static Future<String> getDocumentsDirectory() async {
    try {
      // 获取文档文件夹的路径
      final directory = await getApplicationDocumentsDirectory();
      // 返回文档文件夹的路径
      return directory.path;
    } catch (error) {
      print("Error getting documents directory: $error");
      return "";
    }
  }

  static Future<String> getScreenshotPath() async{
    try {
      // 获取文档文件夹的路径
      final directory = await getApplicationDocumentsDirectory();
      // 返回文档文件夹的路径
      return "${directory.path}\\Screenshot";
    } catch (error) {
      return "";
    }
  }

  static Future<String> getDeviceCoverPath() async{
    try {
      // 获取文档文件夹的路径
      final directory = await getApplicationDocumentsDirectory();
      String path = "${directory.path}\\AdbManager\\DeviceCovers";
      Directory  pathFile = Directory(path);
      if(!pathFile.existsSync()){
        pathFile.createSync(recursive: true);
      }
      // 返回文档文件夹的路径
      return path;
    } catch (error) {
      print("Error getting documents directory: $error");
      return "";
    }
  }

}